home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-30 | 11.2 KB | 359 lines | [TEXT/CWIE] |
- // ===========================================================================
- // LAGACheckBox.cp
- // ===========================================================================
- // “Apple Grayscale Appearance” compliant check box
- // Copyright © 1996 Chrisoft (Christophe ANDRES) All rights reserved.
- //
- // You may use this source code in any application (commercial, shareware, freeware,
- // postcardware, etc), but not remove this notice (no need to acknowledge the use of
- // this class in the about box)
- // You may not sell this source code in any form. This source code may be placed on
- // publicly accessable archive sites and source code disks. It may not be placed on
- // profit archive sites and source code disks without the permission of the author,
- // Christophe ANDRES.
- //
- // This source code is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- //
- // If you make any change or improvement on this class, please send the improved/changed
- // version to : chrisoft@calva.net or Christophe ANDRES
- // 20, rue Prosper Mérimée
- // 67100 STRASBOURG
- // FRANCE
- //
- // ===========================================================================
- // LAGACheckBox.h <- double-click + Command-D to see class declaration
- //
- // LAGACheckBox is my implementation of the “Apple Grayscale Appearance for System 7.5”
- // Check box
- //
- // This class requires AGAColors.cp to be present in your project
- //
- // Version : 1.2
- //
- // Change History (most recent first, date in US form : mm/dd/yy):
- //
- // 06/30/96 ca Public release of version 1.2
- // 06/27/96 ca Changed checks for disabled state (check on triState_On instead of triState_Off)
- // in order that triState_Latent state is drawn as disabled
- // 06/04/96 ca made CW9 adjustments
- // Increased version to 1.2
- // 05/23/96 ca Updated the below changes (05/23/96 M™H) to allow the usage of either the standard checkbox template
- // or the custom LAGACheckBox template. The standard checkbox template is easier for layout
- // because you can see the text, but you cannot define directly a mixed value check box
- // Defined class_ID1 and CreateAGACheckBoxStream1 to handle the two template possibilities
- // Added a CPPb to "LAGACheckBox CPPb.rsrc" called LAGACheckBox1 to handle the standard checkbox
- // template, without having to tinker the class ID
- // Added a static RegisterClass method to simplify the class registration
- // 05/23/96 M™H Changed the stream constructor to use the standard Check box template in Contructor
- // which enables to see the text put in a Check box while defining the view
- // Changed drawing of monochrome checkBox to look like the standard one
- // 05/15/96 ca Increased version to 1.1
- // Added copy constructor
- // Added "on the fly" constructor
- // Replaced UEnvironment::HasFeature(env_SupportsColor) with PaneInColor
- // Added GetDescriptor and SetDescriptor
- // Added change history
- // 04/22/96 ca class made available by Christophe ANDRES <chrisoft@calva.net>
- // (version 1.0)
- //
- // To Do:
- //
-
- #include "LAGACheckBox.h"
-
- #include "AGAColors.h"
-
- #include <UTextTraits.h>
- #include <UEnvironment.h>
- #include <UDrawingState.h>
- #include <LStream.h>
- #include <PP_Messages.h>
- #include <UDrawingUtils.h>
-
- #define kAGACheckBoxWidth 12
- #define kAGACheckBoxHeigth 12
-
- //-------LAGACheckBox class---------------------------------------------------------------------------------------
-
- // begin <05/23/96 ca>
- void LAGACheckBox::RegisterClass ()
-
- {
- // Constructing the class with the LAGACheckBox CPPb
- URegistrar::RegisterClass(LAGACheckBox::class_ID, (ClassCreatorFunc)LAGACheckBox::CreateAGACheckBoxStream);
- // Constructing the class with the standard checkbox template or the LAGACheckBox1 CPPb
- URegistrar::RegisterClass(LAGACheckBox::class_ID1, (ClassCreatorFunc)LAGACheckBox::CreateAGACheckBoxStream1);
- }
-
- LAGACheckBox* LAGACheckBox::CreateAGACheckBoxStream (LStream *inStream)
-
- {
- // Constructing from a 'AGA1' template
- return(new LAGACheckBox(inStream));
- }
-
- LAGACheckBox* LAGACheckBox::CreateAGACheckBoxStream1 (LStream *inStream)
-
- {
- // Constructing from a 'AgA1' template
- return(new LAGACheckBox(inStream, true));
- }
- // end <05/23/96 ca>
-
- //-------Constructors-------------------------------------------------------------------------------------------------
-
- LAGACheckBox::LAGACheckBox ()
-
- {
- mTitle = "\p";
- SetMaxValue(2); // 2 is for mixed value Checkboxes
- }
-
- LAGACheckBox::LAGACheckBox (LStream *inStream, Boolean inCreateWithStdCheckBox) : LControl(inStream)
-
- {
- if (inCreateWithStdCheckBox) // <05/23/96 ca>
- {
- // begin <05/23/96 M™H> mod
- // Change so we can use the standard checkbox template; makes layout easier
- Int16 controlKind;
- Int32 macRefCon;
-
- inStream->ReadData(&controlKind, sizeof(Int16)); // Ignored
- inStream->ReadData(&mTextTraitsID, sizeof(ResIDT));
- inStream->ReadPString(mTitle);
- inStream->ReadData(&macRefCon, sizeof(Int32)); // Ignored
- // end <05/23/96 M™H>
- }
- else
- {
- inStream->ReadData(&mTextTraitsID, sizeof(ResIDT));
- inStream->ReadPString(mTitle);
- }
-
- if (mMaxValue < 2)
- SetMaxValue(2);
- }
-
- // begin <05/15/96 ca>
- LAGACheckBox::LAGACheckBox (const LAGACheckBox &inOriginal) : LControl(inOriginal)
-
- {
- mTextTraitsID = inOriginal.mTextTraitsID;
- mTitle = inOriginal.mTitle;
- if (mMaxValue < 2)
- SetMaxValue(2);
- }
-
- LAGACheckBox::LAGACheckBox (const SPaneInfo &inPaneInfo, MessageT inValueMessage, Int32 inValue,
- ResIDT inTextTraitsID, Str255 inTitle) : LControl(inPaneInfo, inValueMessage, inValue, 0, 2)
- {
- mTextTraitsID = inTextTraitsID;
- mTitle = inTitle;
- }
- // end <05/15/96 ca>
-
- //-------Drawers----------------------------------------------------------------------------------------------------
-
- void LAGACheckBox::DrawSelf ()
-
- {
- DrawGraphic();
- DrawText();
- }
-
- void LAGACheckBox::DrawGraphic (Boolean inPushed)
-
- {
- StColorPenState theState;
- Rect frame;
- Boolean hasColor = ::PaneInColor(this);
- Boolean disabled = (mEnabled != triState_On); // <06/27/96 ca>
-
- theState.Normalize();
-
- CalcLocalFrameRect(frame);
- frame.right = frame.left + kAGACheckBoxWidth;
- frame.bottom = frame.top + kAGACheckBoxHeigth;
-
- // Draw the frame of the checkbox
- if (disabled)
- if (hasColor)
- ::RGBForeColor(&gAGAColorArray[7]);
- else
- ::PenPat(&qd.gray);
-
- ::FrameRect(&frame);
-
- if (!hasColor)
- PenNormal();
-
- ::InsetRect(&frame, 1, 1);
- if (hasColor)
- ::RGBBackColor(inPushed ? &gAGAColorArray[8] : &gAGAColorArray[2]);
- ::EraseRect(&frame);
-
- if (hasColor)
- {
- if (inPushed)
- ::RGBForeColor(&gAGAColorArray[10]);
- else
- ForeColor(whiteColor);
- ::MoveTo(frame.left, frame.bottom - 2);
- ::LineTo(frame.left, frame.top);
- ::LineTo(frame.right - 2, frame.top);
-
- if (inPushed)
- ::RGBForeColor(&gAGAColorArray[6]);
- else
- ::RGBForeColor(mEnabled == triState_On ? &gAGAColorArray[7] : &gAGAColorArray[5]); // <06/27/96 ca>
- ::MoveTo(frame.left + 1, frame.bottom - 1);
- ::LineTo(frame.right - 1, frame.bottom - 1);
- ::LineTo(frame.right - 1, frame.top + 1);
- }
-
- if (mValue)
- {
- if (mValue == 1)
- {
- // Checked state
- if (hasColor)
- {
- ::RGBForeColor(inPushed ? &gAGAColorArray[10] : &gAGAColorArray[5]);
- ::MoveTo(frame.left + 3, frame.bottom - 2);
- ::LineTo(frame.right - 2, frame.top + 3);
- ::MoveTo(frame.right - 2, frame.bottom - 2);
- ::LineTo(frame.right - 2, frame.bottom - 2);
-
- if (mEnabled == triState_On) // <06/27/96 ca>
- ::RGBForeColor(inPushed ? &gAGAColorArray[11] : &gAGAColorArray[8]);
- ::MoveTo(frame.left + 3, frame.bottom - 3);
- ::LineTo(frame.right - 2, frame.top + 2);
- ::MoveTo(frame.right - 2, frame.bottom - 3);
- ::LineTo(frame.right - 2, frame.bottom - 3);
-
- if (mEnabled == triState_On) // <06/27/96 ca>
- ::ForeColor(blackColor);
- else
- ::RGBForeColor(&gAGAColorArray[7]);
- // begin <05/23/96 M™H> mod
- // Make the monochrome version look more like the original
- ::MoveTo(frame.left + 2, frame.top + 1);
- ::LineTo(frame.right - 3, frame.bottom - 4);
- ::MoveTo(frame.left + 2, frame.top + 2);
- ::LineTo(frame.right - 3, frame.bottom - 3);
- ::MoveTo(frame.left + 2, frame.bottom - 4);
- ::LineTo(frame.right - 3, frame.top + 1);
- ::MoveTo(frame.left + 2, frame.bottom - 3);
- ::LineTo(frame.right - 3, frame.top + 2);
- }
- else
- {
- ::MoveTo(frame.left, frame.top);
- ::LineTo(frame.right - 1, frame.bottom - 1);
- ::MoveTo(frame.left, frame.bottom - 1);
- ::LineTo(frame.right - 1, frame.top);
- }
- // end <05/23/96 M™H> mod
- }
- else
- {
- // Mixed state
- if (hasColor)
- {
- ::RGBForeColor(inPushed ? &gAGAColorArray[10] : &gAGAColorArray[5]);
- ::MoveTo(frame.left + 3, frame.top + 6);
- ::LineTo(frame.right - 2, frame.top + 6);
- ::LineTo(frame.right - 2, frame.top + 4);
-
- if (mEnabled == triState_On) // <06/27/96 ca>
- ::ForeColor(blackColor);
- else
- ::RGBForeColor(&gAGAColorArray[7]);
- }
- ::MoveTo(frame.left + 2, frame.top + 4);
- ::LineTo(frame.right - 3, frame.top + 4);
- ::MoveTo(frame.left + 2, frame.top + 5);
- ::LineTo(frame.right - 3, frame.top + 5);
- }
- }
-
- if (inPushed && !hasColor)
- InvertRect(&frame);
- }
-
- void LAGACheckBox::DrawText ()
-
- {
- StColorPenState theState;
- // Retrieve info about font again.
-
- Int16 just = UTextTraits::SetPortTextTraits(mTextTraitsID);
-
- Rect frame;
- CalcLocalFrameRect(frame);
- frame.left += kAGACheckBoxWidth + 5;
- frame.top--;
- frame.bottom--;
- if (UEnvironment::HasFeature(env_SupportsColor))
- {
- RGBColor textColor;
- ::GetForeColor(&textColor);
-
- ApplyForeAndBackColors();
- if (mEnabled == triState_On) // <06/27/96 ca>
- ::RGBForeColor(&textColor);
- else
- ::RGBForeColor(&gAGAColorArray[7]);
- }
- UTextDrawing::DrawWithJustification((Ptr)&mTitle[1], mTitle[0], frame, just);
- }
-
- //-------Utilities--------------------------------------------------------------------------------------------------
-
- StringPtr LAGACheckBox::GetDescriptor (Str255 outDescriptor) const
-
- {
- return LString::CopyPStr(mTitle, outDescriptor);
- }
-
- void LAGACheckBox::SetDescriptor (ConstStr255Param inDescriptor)
-
- {
- mTitle = inDescriptor;
- Refresh();
- }
-
- void LAGACheckBox::SetValue (Int32 inValue)
-
- {
- if (inValue != mValue)
- {
- LControl::SetValue(inValue);
- FocusDraw(); // Redraw to reflect new state
- DrawGraphic();
- }
- }
-
- void LAGACheckBox::HotSpotAction (Int16 /*inHotSpot*/, Boolean inCurrInside, Boolean inPrevInside)
-
- {
- // Draw if cursor moved from IN to OUT
- // or from OUT to IN
- if (inCurrInside != inPrevInside)
- {
- FocusDraw();
- DrawGraphic(inCurrInside);
- }
- }
-
- void LAGACheckBox::HotSpotResult (Int16 /*inHotSpot*/)
-
- {
- SetValue(1 - GetValue());
- }
-
-
-